package com.biz.primus.ms.tms.dao.repository;

import com.biz.primus.model.cat.enums.CatSaleStatusEnum;
import com.biz.primus.model.cat.enums.CatStatus;
import com.biz.primus.ms.base.jpa.repository.CommonJpaRepository;
import com.biz.primus.ms.tms.dao.po.Cat;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author defei
 * @date 2017/9/12
 */
public interface CatRepository extends CommonJpaRepository<Cat, Long>, CatDao {

    List<Cat> findByStatus(CatStatus status);

    List<Cat> findBySaleStatus(CatSaleStatusEnum saleStatus);

    @Transactional
    @Modifying
    @Query("UPDATE Cat cat SET cat.status = :status WHERE cat.id = :id")
    Integer updateStatus(@Param("id") Long id, @Param("status") CatStatus status);
}
